function [bits] = adaptator (x, is_small, prepros_flag, threshold, pros_flag, threshold2, count_for_signs)
%is_small 0=large, 1=small 2=is a matrix of signs
%prepros_flag 0=nothing, 1=logarithm, 2=escape
%pros_flag K = Krichevskiy, A= alg A, L = levenstein, G = golomb
%threshold - for logarithm and code escape
%threshold2 - for golomb code

bits=0;
if (~isempty(x))
    
    if (count_for_signs > 0)
        if (is_small == 1 || count_for_signs == 1)
            non_zero_x = x(x ~= 0);
            sign_matrix = (non_zero_x > 0);
            %bits = bits + adaptive_cost_KT(sign_matrix(:), 2);
            bits = count_bits_for_pros_flag(sign_matrix(:), 2, pros_flag, threshold2);
        else if (is_small == 0 || count_for_signs == 2)
            bits = bits + numel(find(x));
            end
        end
    else
    
        x = abs(round(x(:)));
        %l = length(x);
    
        switch prepros_flag
            case 1 
                [x, b] = logarithm_data(x, threshold);
                bits = bits + b;
            case 2
                x = escape_data (x, threshold);
            otherwise
        end
   
        alphabet_size = max(x) + 1;
        bits = bits + count_bits_for_pros_flag(x, alphabet_size, pros_flag, threshold2);
    end
end
end

function [bits] = count_bits_for_pros_flag(x, alphabet_size, pros_flag, threshold2)
    bits = 0;
    switch pros_flag
            case 'K'
                %let's insert Krichevskiy
                bits = bits + adaptive_cost_KT(x, alphabet_size);
            case 'A'
                %let's insert A
                bits = bits + adaptive_cost_A(x, alphabet_size); 
            case 'L'
                %let's insert Levenstein
                l = length(x);
                for t = 1:l
                    bits = bits + levenstein_code_length(x(t));
                end
            case 'G'
                bits = bits + golomb_data(x, threshold2);
            otherwise
    end;
end